package com.liuwei.msmall.cart.vo;

import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Classname CartVo
 * @Description TODO
 * @Date 2020/6/27 22:14
 * @Created by 刘
 */

/**
 * 需要计算的属性的vo就不需要使用lombok自动生成的setter,getter方法
 */
@ToString
public class CartVo {

    private List<CartItemVo> items;

    private int countType;//商品种类

    private Integer checkedNum;//已选商品数量

    private BigDecimal totalAmount;//所有种类的总计价格

    private BigDecimal reduce=new BigDecimal(0+"");//每个商品的减免信息

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }

    public int getCountType() {

        int count=0;
        if (items!=null&&items.size()>0){
            for (CartItemVo item : items) {
                count+=1;

            }
        }

        return count;
    }


    public Integer getCheckedNum() {
        int count=0;
        if (items!=null&&items.size()>0){
            for (CartItemVo item : items) {
                if (item.getChecked()){
                    count+=item.getCountNum();
                }

            }
        }

        return count;
    }



    public BigDecimal getTotalAmount() {

        BigDecimal decimal = new BigDecimal(0);
        if (items!=null&&items.size()>0){
            for (CartItemVo item : items) {
                if (item.getChecked()){
                    //选中的商品的才计算总价
                    decimal=decimal.add(item.getTotalPrice());
                }

            }
        }

        decimal.subtract(getReduce());
        return decimal;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
